﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Citi.Scheduler.Domain;
using Citi.Scheduler.WebUi.Models;

namespace Citi.Scheduler.WebUi.Controllers
{
    public class EscalationController : ControllerBase<EscalationModel, Escalation>
    {
        public ActionResult Form(int routineId)
        {
            return PartialView(new EscalationModel { RoutineId = routineId });
        }

        //[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        [HttpGet]
        public ActionResult Index(int routineId)
        {
            var escalations = new EscalationModel().CreateModel(new Escalation().SelectByRoutine(routineId));
            return PartialView(escalations);
        }

        public ActionResult ActionForm(int? id, int? routineId)
        {
            var routine = new Routine().SelectById<Routine>(routineId.Value);
            var escalation = new EscalationModel { RoutineId = routine.Id, UserId = routine.ResponsibleId };
            return PartialView(escalation);
            //return ActionBase(id, true);
        }

        [HttpPost]
        public ActionResult ActionForm(EscalationModel model)
        {
            ActionBase(model, true);

            var escalations = new EscalationModel().CreateModel(new Escalation().SelectByRoutine(model.RoutineId));

            return PartialView("Index", escalations);
        }
    }
}
